<h1>Action</h1>

<p>Actions are used to represent stack-based actions, defined by simple byte-codes, 
that are executed by the Flash Player.</p>

<table>

<tr>
<th nowrap>Field Name</th>
<th>Type</th>
<th>Size</th>
<th>Description</th>
</tr>

<tr>
<td nowrap valign="top">type</td>
<td nowrap valign="top">unsigned int</td>
<td nowrap valign="top" align="right">8</td>
<td>The byte-code that indicates the type of action to be executed. Byte-codes
are defined in the range 1..127.</td>
</tr>

</table>

<p>The operations include:</p>

<h2>Stack Manipulation</h2>

<table class="actions">

<tr><th>Action</th><th>Description</th><th>Stack Notation</th><th>Example</th></tr>

<tr valign="top"><td>Pop</td>
    <td>Pop value from the top of the stack.</td>
    <td nowrap valign="top">(valueA -- )</td>
    <td nowrap valign="top">(4 -- )</td></tr>
<tr valign="top"><td>Duplicate</td>
    <td>Duplicate the value at the top of the stack.</td>
    <td nowrap valign="top">(valueA -- valueA valueA)</td>
    <td nowrap valign="top">(4 -- 4 4)</td></tr>
<tr valign="top"><td>Swap</td>
    <td>Swap the top two values on the stack.</td>
    <td nowrap valign="top">(valueA valueB -- valueB valueA)</td>
    <td nowrap valign="top">(4 3 -- 3 4)</td></tr>
</table>

<p>The Push action is used to push literals onto the Stack. See also RegisterCopy which 
copies the value on top of the Stack to one of the Flash Player's internal 
registers.</p>
    
<h2>Arithmetic</h2>

<table class="actions">

<tr><th>Action</th><th>Description</th><th>Stack Notation</th><th>Example</th></tr>

<tr valign="top"><td>Add</td>
    <td>Arithmetic Add: A + B</td>
    <td nowrap valign="top">(numA numB -- num)</td>
    <td nowrap valign="top">(4 3 -- 7)</td></tr>
<tr valign="top"><td>Subtract</td>
    <td>Arithmetic Subtract: A - B</td>
    <td nowrap valign="top">(numA numB -- num)</td>
    <td nowrap valign="top">(4 3 -- 1)</td></tr>
<tr valign="top"><td>Multiply</td>
    <td>Arithmetic Multiply: A * B</td>
    <td nowrap valign="top">(numA numB -- num)</td>
    <td nowrap valign="top">(4 3 -- 12)</td></tr>
<tr valign="top"><td>Divide</td>
    <td>Arithmetic Divide: A / B</td>
    <td nowrap valign="top">(numA numB -- num)</td>
    <td nowrap valign="top">(4 3 -- 1.333)</td></tr>
<tr valign="top"><td>Modulo</td>
    <td>Arithmetic Modulo: A % B</td>
    <td nowrap valign="top">(numA numB -- num)</td>
    <td nowrap valign="top">(4 3 -- 1)</td></tr>
<tr valign="top"><td>Increment</td>
    <td>Add 1 to the value on the stack.</td>
    <td nowrap valign="top">(num -- num)</td>
    <td nowrap valign="top">(3 -- 4)</td></tr>
<tr valign="top"><td>Decrement</td>
    <td>Subtracted 1 from the value on the stack.</td>
    <td nowrap valign="top">(num -- num)</td>
    <td nowrap valign="top">(4 -- 3)</td></tr>
</table>

<p>Arithmetic add is supported by two actions. IntegerAdd was introduced in Flash 4. 
It was replaced in Flash 5 by the more flexible Add action which is able to add 
any two numbers and also concatenate strings. If a string and a number are added 
then the number is converted to its string representation before concatenation.</p>

<h2>Comparison</h2>

<table class="actions">

<tr><th>Action</th><th>Description</th><th>Stack Notation</th><th>Example</th></tr>

<tr valign="top"><td>Less</td>
    <td>LessThan: A &lt; B</td>
    <td nowrap valign="top">(numA numB -- boolean)</td>
    <td nowrap valign="top">(10 9 -- 0 )</tr>
<tr valign="top"><td>StringLess</td>
    <td>String compare: stringA &lt; stringB</td>
    <td nowrap valign="top">(stringA stringB -- boolean)</td>
    <td nowrap valign="top">("abc" "ab" -- 0)</td></tr>
<tr valign="top"><td>Equals</td>
    <td>Equals: A == B</td>
    <td nowrap valign="top">(numA numB -- boolean)</td>
    <td nowrap valign="top">(23 23 -- 1 )</tr>
<tr valign="top"><td>StringEquals</td>
    <td>String compare: stringA == stringB</td>
    <td nowrap valign="top">(stringA stringB -- boolean)</td>
    <td nowrap valign="top">("abc" "abc" -- 1)</td></tr>
<tr valign="top"><td>StrictEquals</td>
    <td>Equals: A === B, are the types as well as the values equal.</td>
    <td nowrap valign="top">(valueA valueB -- boolean)</td>
    <td nowrap valign="top">("23" 23 -- 0 )</tr>
<tr valign="top"><td>Greater</td>
    <td>Greater Than: A > B</td>
    <td nowrap valign="top">(numA numB -- boolean)</td>
    <td nowrap valign="top">(10 9 -- 0 )</tr>
<tr valign="top"><td>StringGreater</td>
    <td>String compare: stringA > stringB</td>
    <td nowrap valign="top">(stringA stringB -- boolean)</td>
    <td nowrap valign="top">("abc" "ab" -- 0)</td></tr>
</table>

<p>The less than comparison is supported by IntegerLess introduced in Flash 4 
and Less introduced in Flash 5. The Less action is more flexible allowing comparison 
between any combination of two numbers and strings. In Flash 4 comparisons were 
only supported on values of the same type using either IntegerLess or StringLess.</p>

<p>The equals comparison is supported by IntegerEquals introduced in Flash 4 and 
Equals introduced in Flash 5. The Equals action is more flexible allowing 
comparison between any combination of two numbers and strings. In Flash 4 
comparisons were only supported on values of the same type using either
IntegerEquals or StringEquals.</p>
    
<h2>Logical</h2>

<table class="actions">

<tr><th>Action</th><th>Description</th><th>Stack Notation</th><th>Example</th></tr>

<tr valign="top"><td>And</td>
    <td>Logical And: A &amp;&amp; B</td>
    <td nowrap valign="top">(numA numB -- boolean)</td>
    <td nowrap valign="top">(3 0 -- 0)</td></tr>
<tr valign="top"><td>Or</td>
    <td>Logical Or: A || B</td>
    <td nowrap valign="top">(numA numB -- boolean)</td>
    <td nowrap valign="top">(3 0 -- 1)</td></tr>
<tr valign="top"><td>Not</td>
    <td>Logical Not: !A</td>
    <td nowrap valign="top">(num -- boolean)</td>
    <td nowrap valign="top">(3 -- 0)</td></tr>
</table>
    
<h2>Bitwise</h2>

<table class="actions">

<tr><th>Action</th><th>Description</th><th>Stack Notation</th><th>Example</th></tr>

<tr valign="top"><td>BitwiseAnd</td>
    <td>Bitwise And: A &amp; B</td>
    <td nowrap valign="top">(numA numB -- num)</td>
    <td nowrap valign="top">(5 4 -- 4)</td></tr>
<tr valign="top"><td>BitwiseOr</td>
    <td>Bitwise Or: A | B</td>
    <td nowrap valign="top">(numA numB -- num)</td>
    <td nowrap valign="top">(5 4 -- 5)</td></tr>
<tr valign="top"><td>BitwiseXOr</td>
    <td>Bitwise Exclusive-Or: A ^ B</td>
    <td nowrap valign="top">(numA numB -- num)</td>
    <td nowrap valign="top">(5 4 -- 1)</td></tr>
<tr valign="top"><td>LogicalShiftLeft</td>
    <td>Logical Shift Left: A << B</td>
    <td nowrap valign="top">(numA numB -- num)</td>
    <td nowrap valign="top">(4 1 -- 8)</td></tr>
<tr valign="top"><td>LogicalShiftRight</td>
    <td>Logical Shift Right: A >>> B</td>
    <td nowrap valign="top">(numA numB -- num)</td>
    <td nowrap valign="top">(8 1 -- 4)</td></tr>
<tr valign="top"><td>ArithmeticShiftRight</td>
    <td>Arithmetic Shift Right (sign extension): A >> B</td>
    <td nowrap valign="top">(numA numB -- num)</td>
    <td nowrap valign="top">(-1 1 -- -1)</td></tr>
</table>

<h2>String</h2>

<table class="actions">

<tr><th>Action</th><th>Description</th><th>Stack Notation</th><th>Example</th></tr>

<tr valign="top"><td>StringAdd</td>
    <td>Concatenate two strings</td>
    <td nowrap valign="top">(string string -- string)</td>
    <td nowrap valign="top">("ab" "cd" -- "abcd")</td></tr>
<tr valign="top"><td>StringLength</td>
    <td>Returns the length of a string</td>
    <td nowrap valign="top">(string -- num)</td>
    <td nowrap valign="top">("abc" -- 3)</td></tr>
<tr valign="top"><td>MBStringLength</td>
    <td>Returns the length of a string that contains characters from an extended set such as Unicode.</td>
    <td nowrap valign="top">(string -- num)</td>
    <td nowrap valign="top">("abc" -- 3)</td></tr>
<tr valign="top"><td>StringExtract</td>
    <td>Substring. Extract <I>count</I> characters from string starting at position <em>index</em>.</td>
    <td nowrap valign="top">(count index string -- string)</td>
    <td nowrap valign="top">(3 2 "abcde" -- "bcd")</td></tr>
<tr valign="top"><td>MBStringExtract</td>
    <td>Multi-byte Substring. Extract <I>count</I> characters from string starting at position <em>index</em>.</td>
    <td nowrap valign="top">(count index string -- string)</td>
    <td nowrap valign="top">(3 2 "abcde" -- "bcd")</td></tr>
</table>

<h2>Type Conversion</h2>

<table class="actions">

<tr><th>Action</th><th>Description</th><th>Stack Notation</th><th>Example</th></tr>

<tr valign="top"><td>ToInteger</td>
    <td>Converts the value to an integer</td>
    <td nowrap valign="top"> ( num -- num)</td>
    <td nowrap valign="top"> ( 3.2 -- 3 )</tr>
<tr valign="top"><td>ToNumber</td>
    <td>Converts the string value to a number.</td>
    <td nowrap valign="top"> ( string -- num)</td>
    <td nowrap valign="top"> ( "3.2" -- 3.2 )</tr>
<tr valign="top"><td>ToString</td>
    <td>Converts the value to a string.</td>
    <td nowrap valign="top"> ( num -- string)</td>
    <td nowrap valign="top"> ( 3.2 -- "3.2" )</tr>
<tr valign="top"><td>CharToAscii</td>
    <td>Convert the first character of a string to its ASCII value.</td>
    <td nowrap valign="top">(string -- num)</td>
    <td nowrap valign="top">("abc" -- 97)</td></tr>
<tr valign="top"><td>MBCharToAscii</td>
    <td>Convert the first character of string to its Unicode value.</td>
    <td nowrap valign="top">(string -- num)</td>
    <td nowrap valign="top">("abc" -- 61)</td></tr>
<tr valign="top"><td>AsciiToChar</td>
    <td>Convert the ASCII value to the equivalent character.</td>
    <td nowrap valign="top">(num -- string)</td>
    <td nowrap valign="top">(97 -- "a")</td></tr>
<tr valign="top"><td>MBAsciiToChar</td>
    <td>Convert a Unicode value to the equivalent character.</td>
    <td nowrap valign="top">(num -- string)</td>
    <td nowrap valign="top">(61 -- "a")</td></tr>
</table>

<h2>Variables</h2>

<table class="actions">

<tr><th>Action</th><th>Description</th><th>Stack Notation</th><th>Example</th></tr>

<tr valign="top"><td>GetVariable</td>
    <td>Push the value for the specified variable on the stack</td>
    <td nowrap valign="top">(variableName -- value)</td>
    <td nowrap valign="top">("FlashVersion" -- 4)</td></tr>
<tr valign="top"><td>SetVariable</td>
    <td>Set the value of the specified variable</td>
    <td nowrap valign="top">(variableName value --)</td>
    <td nowrap valign="top">("Var1" 123 --)</td></tr>
<tr valign="top"><td>GetType</td>
    <td>Returns the type of the object or value at the top of the stack.</td>
    <td nowrap valign="top">(value -- value type)</td>
    <td nowrap valign="top">(--)</td></tr>
<tr valign="top"><td>NewVariable</td>
    <td>Create a new user-defined variable.</td>
    <td nowrap valign="top">(name --)</td>
    <td nowrap valign="top">("x" --)</td></tr>
<tr valign="top"><td>InitVariable</td>
    <td>Create and initialise a user-defined variable.</td>
    <td nowrap valign="top">(value name --)</td>
    <td nowrap valign="top">(1 "x" --)</td></tr>
<tr valign="top"><td>NewArray</td>
    <td>Create an array.</td>
    <td nowrap valign="top">(value+ count -- array)</td>
    <td nowrap valign="top">(1 2 3 4 4 -- array)</td></tr>
<tr valign="top"><td>DeleteVariable</td>
    <td>Deletes a variable, returning true if the variable was deleted, false otherwise.</td>
    <td nowrap valign="top">(name -- boolean)</td>
    <td nowrap valign="top">("x" -- 1)</td></tr>
<tr valign="top"><td>Delete</td>
    <td>Deletes an object or variable, returning true if the object was deleted, false otherwise.</td>
    <td nowrap valign="top">(name -- boolean)</td>
    <td nowrap valign="top">("x" -- 1)</td></tr>
</table>

<h2>Functions</h2>

<table class="actions">

<tr><th>Action</th><th>Description</th><th>Stack Notation</th><th>Example</th></tr>

<tr valign="top"><td>ExecuteFunction</td>
    <td>Execute the built-in function.</td>
    <td nowrap valign="top">(arg* functionName -- result*)</td>
    <td nowrap valign="top">(12.3 "isFinite" -- "1")</td></tr>
<tr valign="top"><td>Return</td>
    <td>Return control from the function.</td>
    <td nowrap valign="top">(--)</td>
    <td nowrap valign="top">(--)</td></tr>
</table>

<h2>Objects</h2>

<table class="actions">

<tr><th>Action</th><th>Description</th><th>Stack Notation</th><th>Example</th></tr>

<tr valign="top"><td>GetAttribute</td>
    <td>Push the value of an objects attribute on the stack</td>
    <td nowrap valign="top">(string string -- value)</td>
    <td nowrap valign="top">("Key" "SPACE" -- 32)</td></tr>
<tr valign="top"><td>SetAttribute</td>
    <td>Set the value of a attribute of an object</td>
    <td nowrap valign="top">(variable string value --)</td>
    <td nowrap valign="top">(&lt;_root&gt; "variable" 1 --)</td></tr>
<tr valign="top"><td>ExecuteMethod</td>
    <td>Execute a method of an object</td>
    <td nowrap valign="top">(string string -- value)</td>
    <td nowrap valign="top">("Key" "getCode" -- num)</td></tr>
<tr valign="top"><td>NewMethod</td>
    <td>Define a new method for an object</td>
    <td nowrap valign="top">&nbsp;</td>
    <td nowrap valign="top">&nbsp;</td></tr>
<tr valign="top"><td>NamedObject</td>
    <td>Construct an instance of a built-in object.</td>
    <td nowrap valign="top">(arg* count className -- instance)</td>
    <td nowrap valign="top">("My String" 1 "String" -- instance)</td></tr>
<tr valign="top"><td>NewObject</td>
    <td>Define a new class.</td>
    <td nowrap valign="top">((name value)* count -- instance)</td>
    <td nowrap valign="top">("Account" "123456" 1 -- value)</td></tr>
<tr valign="top"><td>Enumerate</td>
    <td>Enumerate through the attributes of the object referenced by the name of the variable on the stack.</td>
    <td nowrap valign="top">( "var" -- )</td>
    <td nowrap valign="top">( -- )</td></tr>
<tr valign="top"><td>EnumerateObject</td>
    <td>Enumerate through the attributes of the object on the stack.</td>
    <td nowrap valign="top">( "var" -- )</td>
    <td nowrap valign="top">( -- )</td></tr>
</table>

<h2>Movie Control</h2>

<table class="actions">

<tr><th>Action</th><th>Description</th><th>Stack Notation</th><th>Example</th></tr>

<tr valign="top"><td>GetTarget</td>
    <td>Returns a string representing the path to the movie clip in which the current action is executed.</td>
    <td nowrap valign="top">(-- clipName )</td>
    <td nowrap valign="top">( -- "_root/MovieClip")</td></tr>
<tr valign="top"><td>SetTarget2</td>
    <td>Change the context of the Flash Player so subsequent actions are applied to the movie clip, <i>clipName</i>.</td>
    <td nowrap valign="top">(clipName -- )</td>
    <td nowrap valign="top">("MovieClip" --)</td></tr>
<tr valign="top"><td>GetProperty</td>
    <td>Push the value of the specified property on the stack. Properties are identified by reserved values, see the Push action for more details.</td>
    <td nowrap valign="top">(value -- value)</td>
    <td nowrap valign="top">( &lt;_totalframes&gt; -- 36 )</td></tr>
<tr valign="top"><td>SetProperty</td>
    <td>Set the value of a property</td>
    <td nowrap valign="top">(value propertyName --)</td>
    <td nowrap valign="top">( 8000 &lt;_width&gt; -- )</td></tr>
<tr valign="top"><td>CloneSprite</td>
    <td>Duplicate a movie clip <i>clipName</i>, on the display list layer <i>depth</i> with the name <i>newName</i>.</td>
    <td nowrap valign="top">( depth clipName newName --)</td>
    <td nowrap valign="top">( 19 "_root/MovieClip" "newClip" -- )</td></tr>
<tr valign="top"><td>RemoveSprite</td>
    <td>Delete a movie clip</td>
    <td nowrap valign="top">( clipName --)</td>
    <td nowrap valign="top">( "_root/MovieClip" -- )</td></tr>
<tr valign="top"><td>StartDrag</td>
    <td>Starts dragging a movie clip with an optional constraining rectangle defined by the corner points (x1,y1), (x2,y2).</td>
    <td nowrap valign="top">( x1 y1 x2 y2 1 clipName --)<br><br>( 0 clipName --)</td>
    <td nowrap valign="top">( 0 0 400 400 1 "movieClip" - )<br><br>( 0 "movieClip" - )</td></tr>
<tr valign="top"><td>EndDrag</td>
    <td>Stops dragging a movie clip</td>
    <td nowrap valign="top">(--)</td>
    <td nowrap valign="top">&nbsp;</td></tr>
<tr valign="top"><td>NextFrame</td>
    <td>Go to the next frame of the current movie</td>
    <td nowrap valign="top">(--)</td>
    <td nowrap valign="top">&nbsp;</td></tr>
<tr valign="top"><td>PreviousFrame</td>
    <td>Go to the previous frame of the current movie</td>
    <td nowrap valign="top">(-- )</td&nbsp;>
    <td nowrap valign="top">&nbsp;</td></tr>
<tr valign="top"><td>Play</td>
    <td>Start playing the current movie at the current frame</td>
    <td nowrap valign="top">(--)</td>
    <td nowrap valign="top">&nbsp;</td></tr>
<tr valign="top"><td>Stop</td>
    <td>Stop playing the current movie</td>
    <td nowrap valign="top">(--)</td>
    <td nowrap valign="top">&nbsp;</td></tr>
<tr valign="top"><td>ToggleQuality</td>
    <td>Toggle the movie between high and low quality</td>
    <td nowrap valign="top">(--)</td>
    <td nowrap valign="top">&nbsp;</td></tr>
<tr valign="top"><td>StopSounds</td>
    <td>Stop playing all sounds</td>
    <td nowrap valign="top">(--)</td>
    <td nowrap valign="top">&nbsp;</td></tr>
</table>    
    
<h2>ActionScript 2.0</h2>

<p>Starting with Flash 6 Macromedia extended the syntax of ActionScript to make 
it more object-oriented, moving the language closer to Java than JavaScript. 
Several actions were added to support the new keywords introduced into ActionScript 
2.0.</p>

<table class="actions">

<tr><th>Action</th><th>Description</th><th>Stack Notation</th><th>Example</th></tr>

<tr valign="top"><td>InstanceOf</td>
    <td>Return true or false to the stack if the object can be created using the constructor function.</td>
    <td nowrap valign="top">( object function -- true | false)</td>
    <td nowrap valign="top">&nbsp;</td></tr>
<tr valign="top"><td>Implements</td>
    <td>Identifies a class implements a defined interface.</td>
    <td nowrap valign="top">( (function) count function --)</td>
    <td nowrap valign="top">&nbsp;</td></tr>
<tr valign="top"><td>Extends</td>
    <td>Identifies that a class inherits from a class - used to increase the execution speed of ActionScript code.</td>
    <td nowrap valign="top">( subclass superclass --)</td>
    <td nowrap valign="top">&nbsp;</td></tr>
<tr valign="top"><td>Cast</td>
    <td>Casts the type of an object on the stack, returning the object if it is the same type as the constructor function, null otherwise.</td>
    <td nowrap valign="top">(function object -- object | null)</td>
    <td nowrap valign="top">&nbsp;</td></tr>
<tr valign="top"><td>Throw</td>
    <td>Throw an exception.</td>
    <td nowrap valign="top">(--)</td>
    <td nowrap valign="top">&nbsp;</td></tr>
</table>
    
<h2>Miscellaneous</h2>

<table class="actions">

<tr><th>Action</th><th>Description</th><th>Stack Notation</th><th>Example</th></tr>

<tr valign="top"><td>Trace</td>
    <td>Append value to debugging window</td>
    <td nowrap valign="top">(value --)</td>
    <td nowrap valign="top">("X = 3" --)</td></tr>
<tr valign="top"><td>GetTime</td>
    <td>Push the number of milliseconds that have elapsed since the player started on the stack.</td>
    <td nowrap valign="top">(-- num)</td>
    <td nowrap valign="top">(-- 1274832)</td></tr>
<tr valign="top"><td>RandomNumber</td>
    <td>Push a random number on the stack.</td>
    <td nowrap valign="top">(maximumValue -- num)</td>
    <td nowrap valign="top">(10 -- 3)</td></tr>
</table>

<p><b>Notes</b></p>

<div style="padding-left:20px; margin-bottom:10px;">
<ul>
<li>The Add action was updated in Flash 5 so it can be used to perform arithmetic 
add and string concatenation depending on whether the values on the stack can be 
interpreted as numeric values or strings. The original add action (Code = 10) 
should not be used.</li>

<li>For the division operation, if a divide by zero error occurs then the string 
"#ERROR" is pushed onto the stack.</li>

<li>The Equals and Less actions were updated in Flash 5 so it can be used to 
perform arithmetic and string comparison depending on whether the values on the 
stack can be interpreted as numeric values or strings. The original Less action 
(code = 15) and Equals action (code = 14) should not be used.</li>

<li>Type conversion of string characters is now handled by the String object, 
introduced in Flash 5. The ToInteger action is now supported by the Math object 
also introduced in Flash 5. The type conversion functions are only included for 
completeness.</li>

<li>Flash version 5 supports built-in and user defined objects. For a full 
description of the objects supported please consult an ActionScript 5 reference 
guide.</li>
</ul>
</div>

<h2>History</h2>
<p>A limited set of byte-codes were introduced in Flash 4. This was greatly
expanded in Flash 5 with the wholesale adoption of a stack-based execution 
model for all actions.</p>

